#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define LEN (1024)
int main(void) {
	FILE *fp = NULL;
	char *buf = NULL;
	char *str = "for trace test";
	int len = 0;

	len = strlen(str)+1;
	buf = (char *)malloc(LEN);
	if(NULL == buf) {
		return -1;
	}
	memset(buf, 0, LEN);

	// open and write data to file
	fp = fopen("a.txt", "w+");
	fwrite(str, len, 1, fp);

	// read data
	fseek(fp, 0, SEEK_SET);
	fread(buf, len, 1, fp);

	printf("%s\n", buf);
	fclose(fp);
	free(buf);

	return(0);
}
